package com.njmaomao.gj.pyot.domain.wechat.wechatapi.refundquery;

import com.njmaomao.gj.pyot.config.Bizs;
import com.njmaomao.gj.pyot.domain.wechat.PayConfig;
import com.thoughtworks.xstream.annotations.XStreamAlias;

/**
 * 查询退款入参
 * @author hh 2018-5-10
 */
@XStreamAlias("xml")
public class RefundQueryReq {

    // 公众账号ID 必填[是] 微信支付分配的公众账号ID（企业号corpid即为此appId）
    private String appid;

    // 商户号 必填[是] 微信支付分配的商户号
    @XStreamAlias("mch_id")
    private String mchId;

    // 随机字符串 必填[是] 随机字符串，不长于32位。推荐随机数生成算法
    @XStreamAlias("nonce_str")
    private String nonceStr;

    // 签名 必填[是] 签名，详见签名生成算法
    private String sign;

    // 签名类型 必填[否] 签名类型，目前支持HMAC-SHA256和MD5，默认为MD5
    @XStreamAlias("sign_type")
    private String signType;

    // 微信订单号 必填[四选一] 微信订单号查询的优先级是： refund_id > out_refund_no > transaction_id > out_trade_no
    @XStreamAlias("transaction_id")
    private String transactionId;

    // 商户订单号 必填[四选一]
    @XStreamAlias("out_trade_no")
    private String outTradeNo;

    // 商户退款单号 必填[四选一]
    @XStreamAlias("out_refund_no")
    private String outRefundNo;

    // 微信退款单号 必填[四选一]
    @XStreamAlias("refund_id")
    private String refundId;

    // 偏移量 必填[否] 偏移量，当部分退款次数超过10次时可使用，表示返回的查询结果从这个偏移量开始取记录
    private int offset;

    public String getAppid() {
        return appid;
    }

    public String getMchId() {
        return mchId;
    }

    public String getNonceStr() {
        return nonceStr;
    }

    public String getSign() {
        return sign;
    }

    public String getSignType() {
        return signType;
    }

    public String getTransactionId() {
        return transactionId;
    }

    public String getOutTradeNo() {
        return outTradeNo;
    }

    public String getOutRefundNo() {
        return outRefundNo;
    }

    public String getRefundId() {
        return refundId;
    }

    public int getOffset() {
        return offset;
    }

    public static RefundQueryReq build(PayConfig payConfig, String refundOrderCode) {
        RefundQueryReq refundQueryReq = new RefundQueryReq();
        refundQueryReq.appid = payConfig.getAppid();
        refundQueryReq.mchId = payConfig.getMchId();
        refundQueryReq.nonceStr = Bizs.generateNonceStr();
        refundQueryReq.outTradeNo = refundOrderCode;
        refundQueryReq.signType = Bizs.SIGN_TYPE;
        refundQueryReq.sign = Bizs.getMd5Sign(refundQueryReq, payConfig.getKey());
        return refundQueryReq;
    }

}
